<template>
    <div>
      <!-- <button @click="exportData">导出数据</button> -->
      <el-button type="primary" @click="export2Excel">导出Excel表格</el-button>
      <h2>{{this.$store.state.user.userInfo.roleId}}</h2>
      <span v-show="this.$store.state.user.userInfo.roleId === 1">admin</span>

    </div>

</template>

<script>

export default {
  data () {
    return {
      tableData: [
        { row1: '123', row2: '111', row3: '112' },
        { row1: '123', row2: '111', row3: '112' },
        { row1: '123', row2: '111', row3: '112' },
        { row1: '123', row2: '111', row3: '112' },
        { row1: '123', row2: '111', row3: '112' }
      ]
    }
  },
  methods: {
    formatJson (filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => v[j]))
    },
    export2Excel () {
      require.ensure([], () => {
        const { export_json_to_excel } = require('../../vendor/Export2Excel.js')
        const tHeader = ['row', 'row2', 'row3']
        const filterVal = ['row1', 'row2', 'row3']
        const list = this.tableData
        const data = this.formatJson(filterVal, list)
        export_json_to_excel(tHeader, data, '气象站数据列表')
      })
    }
  }
}
</script>
